export const useLoogPress = function () {
    const events = {}
    return {
        press(key) {
            let isPress = false
            const keydown = (e) => {
               e.keyCode === key && (isPress = true)
            }
            let keyup = (e) => {
                e.keyCode === key && (isPress = false)
            }
            window.addEventListener('keydown', keydown)
            window.addEventListener('keyup', keyup)
            events[key] = {
                keydown,
                keyup
            }
            return () => {
                return isPress
            }
        },
        clear(key) {
            if(!events[key]) return
            const {
                keydown,
                keyup
            } = events[key]
            window.removeEventListener('keydown', keydown)
            window.removeEventListener('keyup', keyup)
            events.keydown = null
            events.keyup = null
            events[key] = null
        }
    }
}